package com.jic.member.controller.manage;
import com.jic.common.base.vo.PageResult;
import com.jic.common.base.vo.RestResult;
import com.jic.member.entity.MemberRoster;
import com.jic.member.request.MemMemberRosterBatchRequest;
import com.jic.member.request.MemMemberRosterRequest;
import com.jic.member.service.MemMemberRosterService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.List;

/**
 * @author
 */

@ApiOperation(value = "特殊名单controller")
@Slf4j
@RestController
@RequestMapping("/memMemberRoster")
public class MemMemberRosterController {

    @Autowired
    private MemMemberRosterService memMemberRosterService;

    @ApiOperation(value = "获取特殊名单列表")
    @ResponseBody
    @RequestMapping(value = "/queryList")
    public RestResult<PageResult<MemberRoster>> queryList(@RequestBody MemMemberRosterRequest form) {
        return memMemberRosterService.queryPage(form);
    }

    @ApiOperation("修改特殊名单")
    @RequestMapping("update")
    public RestResult<Long> update(@RequestBody MemMemberRosterRequest param){
        return RestResult.success(memMemberRosterService.update(param));
    }

    @ApiOperation("删除特殊名单")
    @RequestMapping("delete")
    public RestResult<Long> delete(@RequestBody MemMemberRosterRequest param){
        return RestResult.success( memMemberRosterService.delete(param.getId()));
    }


    @ApiOperation("新增特殊名单")
    @RequestMapping("addMemMemberRoster")
    public RestResult addMemMemberRoster(@RequestBody MemMemberRosterRequest request){
        RestResult  restResult= memMemberRosterService.insert(request);
        return restResult;
    }

    @ApiOperation("批量保存特殊名单")
    @RequestMapping("addBatchMemMemberRoster")
    public RestResult addBatchMemMemberRoster(@RequestBody MemMemberRosterBatchRequest request){
        RestResult  restResult= memMemberRosterService.insert(request);
        return restResult;
    }

    @ResponseBody
    @PostMapping(value = "/importExcel")
    public RestResult<List> importExcel(@RequestParam("file") MultipartFile file) throws IOException {


        String fileName  = file.getOriginalFilename();
        FileInputStream fileInputStream = (FileInputStream) file.getInputStream();

        List<String>  result =memMemberRosterService.importExcel(fileName,fileInputStream);

        return RestResult.success(result);
    }


}
